package com.xunkids.bos.migration.component.bos;

import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.bos.BosClient;
import com.baidubce.services.bos.BosClientConfiguration;
import com.baidubce.services.bos.model.BosObject;
import com.xunkids.bos.migration.common.constant.BusinessConstant;

/**
 * @program: migration
 * @author: byl
 * @create: 2024-03-20 14:21
 * @Description 百度对象存储
 */


public class BOSStorage {







    private static class SingletonHolder{
        private static final BOSStorage instance = new BOSStorage();


    }

    //获取单例的方法
    public static  BOSStorage getInstance(){
        return SingletonHolder.instance;
    }

    public  BosClient getBosClient(){
        BosClientConfiguration config = new BosClientConfiguration();
        config.setCredentials(new DefaultBceCredentials(BusinessConstant.BAIDU_ACCESS_KEY_ID, BusinessConstant.BAIDU_ACCESS_KEY_SECRET));
        config.setEndpoint(BusinessConstant.BAIDU_END_POINT);
        return new BosClient(config);
    }




    private BOSStorage() {

    }


    /**
     * @param bucketName
     * @param key        路径+文件名
     * @return 获取Bos对象
     */
    public  BosObject getObject(String bucketName, String key,BosClient client) {
        return client.getObject(bucketName, key);

    }




}
